<template>
  <div class="waiting-info">
    <div class="list-item-setting" v-if="!optionsInfo.ListLocaleSys">
      <div class="title-info">
        <el-divider content-position="left">列表区域设置</el-divider>
      </div>
      <el-form-item label="展示行数">
        <el-input-number
          :min="4"
          :max="6"
          v-model="optionsInfo['showRowNums']"
          class="hide-spin-button"
          size="small"
          @change="handleTotal"
        />
      </el-form-item>
      <el-form-item label="行高" v-if="false">
        <el-input-number
          v-model="optionsInfo['lineHeight']"
          :min="0"
          size="small"
          class="hide-spin-button"
        />
      </el-form-item>
      <el-form-item label="内容高度">
        <el-input-number
          v-model="optionsInfo['contentHeight']"
          :min="0"
          size="small"
          class="hide-spin-button"
        />
      </el-form-item>
    </div>

    <div class="list-item-setting" v-if="!optionsInfo.DataDisplayRuleSys">
      <el-divider content-position="left">数据显示规则</el-divider>
      <el-form-item label="规则显示" class="call-patient-set">
        <el-checkbox-group
          v-if="ruleOptions&&ruleOptions.length"
          v-model="optionsInfo['queryRule']">
          <el-checkbox
            v-for="item in ruleOptions"
            :label="item.value"
            :key="item.value"
            @change="(e)=>handleRuleChange(e, item)"
          >
            {{ item.label }}
          </el-checkbox>
        </el-checkbox-group>
      </el-form-item>
    </div>

    <div class="list-title-setting" v-if="!optionsInfo.ListHeaderSettingsSys">
      <div class="title-info">
        <el-divider content-position="left">列表头部设置</el-divider>
      </div>

      <el-form-item label="是否显示">
        <el-switch v-model="optionsInfo['headShow']"/>
      </el-form-item>
      <el-form-item label="背景颜色">
        <el-color-picker
          size="small"
          show-alpha
          :predefine="predefineColors"
          v-model="optionsInfo['headerBackgroundColor']"/>
      </el-form-item>
      <el-form-item label="字体颜色">
        <el-color-picker
          size="small"
          show-alpha
          :predefine="predefineColors"
          v-model="optionsInfo['headerFontColor']"/>
      </el-form-item>
      <el-form-item label="字号设置">
        <el-input-number
          v-model="optionsInfo['headFontSize']"
          :min="12"
          size="small"
          class="hide-spin-button"
        />
      </el-form-item>
      <el-form-item label="粗细设置">
        <el-select v-model="optionsInfo['headFontWeight']" placeholder="请选择">
          <el-option
            v-for="item in fontWeightOptions"
            :key="item.value"
            :label="item.label"
            :value="item.value">
          </el-option>
        </el-select>
      </el-form-item>


      <el-form-item class="col-info">
        <div class="title">
          <el-divider content-position="center">显示列</el-divider>
        </div>
        <div class="options-info row-option">
          <el-checkbox-group v-model="optionsInfo['defaultShowCol']">
            <Draggable
              class="list-group"
              @end="handleDragEnd"
              :list="optionsInfo['colOptions']"
              :animation="100"
            >
              <el-checkbox
                v-for="(item,index) in (optionsInfo['colOptions'])"
                :key="index"
                :label="item.value"
                :disabled="isDisabled(item.value)"
              >
                <div class="setting-info">
                  <el-input v-model="item.label" placeholder="请输入内容" size="small"/>
                  <el-input
                    type="number"
                    :min="0.1"
                    :max="7"
                    :step="0.1"
                    :precision="1"
                    @change.native.prevent="(e)=>handleChangeWidth(e)"
                    v-model="item.flex" placeholder="请输入列宽" size="small"/>
                    <el-color-picker
                      v-model="item.color"
                      size="small"
                      show-alpha
                      :predefine="predefineColors"
                    />
                </div>
                <i class="el-icon-thumb"></i>
              </el-checkbox>
            </Draggable>
          </el-checkbox-group>
        </div>
      </el-form-item>

      <div class="list-item-setting" v-if="optionsInfo['defaultShowCol'].includes('deptName')">
        <div class="title-info">
          <el-divider content-position="left">科室设置</el-divider>
        </div>
        <div class="content">
          <deptNameKeyEditor
            :designer="designer"
            :option-model="optionModel"
            :selected-widget="selectedWidget"
          />
        </div>
      </div>

      <div class="list-item-setting" v-if="optionsInfo['defaultShowCol'].includes('treatmentRoomName')">
        <div class="title-info">
          <el-divider content-position="left">诊室设置</el-divider>
        </div>
        <div class="content">
          <roomNameKeyEditor
            businessType="special"
            :designer="designer"
            :selected-widget="selectedWidget"
            :option-model="optionModel"
          />
        </div>
      </div>
    </div>

    <el-form-item class="register-info" v-if="(optionsInfo['defaultShowCol']).includes('registerObjNames')">
      <div class="title">
        <el-divider content-position="center">号别类型</el-divider>
      </div>
      <div class="options-info">
        <el-radio-group v-model="optionsInfo['registerObjNameKey']">
          <el-radio
            :label="item.dictValue"
            :value="item.dictValue"
            :key="item.dictValue"
            v-for="item in registerObjNameOptions"
          >
            {{ item.dictLabel }}
          </el-radio>
        </el-radio-group>
      </div>
    </el-form-item>

    <div class="list-scroll-setting" v-if="!optionsInfo.ListSettingSys">
      <div class="title-info">
        <el-divider content-position="left">列表设置</el-divider>
      </div>
      <el-form-item label="候诊类型设置" class="wait-patient-set">
        <el-radio-group v-model="optionsInfo.waitPatientType">
          <el-radio :label="item.value" v-for="item in waitPatientTypeOptions" :key="item.value">
            {{ item.label }}
          </el-radio>
        </el-radio-group>
      </el-form-item>

      <el-form-item label="字号设置">
        <el-input-number
          v-model="optionsInfo['itemFontSize']"
          :min="12"
          size="small"
          class="hide-spin-button"
        />
      </el-form-item>

      <el-form-item label="粗细设置">
        <el-select v-model="optionsInfo['itemFontWeight']" placeholder="请选择">
          <el-option
            v-for="item in fontWeightOptions"
            :key="item.value"
            :label="item.label"
            :value="item.value">
          </el-option>
        </el-select>
      </el-form-item>

      <el-form-item label="滚动速度(设备比例*19.2*速率/s)" class="column-area" v-if="fieldHas('listSpeed')">
        <el-input-number :precision="1" :min="1" size="small" v-model="optionsInfo['listSpeed']"/>
      </el-form-item>

      <el-form-item label="切屏时间(s)" class="switching-screen">
        <el-input-number
          :min="10"
          :step="1"
          size="small"
          class="hide-spin-button"
          v-model="optionsInfo['switchTime']"
          :disabled="!(optionsInfo['switchScreen'])"
        />
      </el-form-item>
    </div>

    <!--弹曾选择-->
    <div class="list-item-setting" v-if="optionsInfo['layerEdit']">
      <el-divider content-position="left">弹层选择</el-divider>
      <el-form-item class="call-patient-set">
        <el-select v-model="optionsInfo['layerNameKey']" placeholder="请选择">
          <el-option
            v-for="item in layerNameOptions"
            :key="item.value"
            :label="item.label"
            :value="item.value">
          </el-option>
        </el-select>
      </el-form-item>
    </div>
  </div>
</template>

<script>
import Draggable from "vuedraggable"
import constantDic from "@/utils/vue-i18n/lang/zh-CN";
import * as types from "@c/public/form-designer/devType/datas-types";
import roomNameKeyEditor from "@detailsEdit/scene-edit/basicInfo/roomNameKey-editor.vue";
import deptNameKeyEditor from "@detailsEdit/scene-edit/basicInfo/deptNameKey-editor.vue";

export default {
  name: "waitingInfoNxConfig-editor",

  componentName: "waitingInfoNxConfig-editor",

  components: {
    Draggable,
    deptNameKeyEditor,
    roomNameKeyEditor,
  },

  mixins: [],

  props: {
    designer: Object,
    selectedWidget: Object,
    optionModel: Object,
  },

  inject: ['serverFieldList', 'getDesignerConfig'],

  data() {
    return {
      constantDic: constantDic,
      predefineColors: types['predefineColors'],
      waitPatientTypeOptions:types['waitPatientTypeOptions'],
      callPatientOptions: [
        {
          value: 1,
          label: '科室'
        },
        {
          value: 2,
          label: '号别'
        },
        {
          value: 3,
          label: '诊室'
        },
        {
          value: 4,
          label: '医生工作站'
        }
      ],
      ruleOptions: [
        {
          value: 1,
          label: '医生'
        },
        {
          value: 2,
          label: '号别'
        }
      ],
      optionsInfo: Object(),
      mergeOptions: [
        {label: '科室', value: 'deptName', state: false, disabled: false, display: false},
        {label: '诊室', value: 'treatmentRoomName', state: false, disabled: false, display: true},
        {label: '医生', value: 'workerName', state: false, disabled: false, display: false},
        {label: '号别', value: 'registerObjNames', state: false, disabled: false, display: true},
        {label: '人数', value: 'waitPatientCount', state: false, disabled: false, display: false},
      ],
      fontWeightOptions: types['fontWeightOptions'],
      layerNameOptions: types['layerNameOptions']

    }
  },

  computed: {
    // 判断字段是否存在
    fieldHas() {
      return function (field) {
        return Reflect.has(this.optionsInfo, field)
      }
    },

    isDisabled() {
      return function (val) {
        // let arr = ['deptName', 'treatmentRoomName', 'workerName'];
        let arr = Array();
        return arr.includes(val);
      }
    },

    registerObjNameOptions() {
      return this.$store.getters['templateDetails/getRegisterObjNameOptions']
    }
  },

  methods: {
    // 更改合并项
    handleMergeCol(event, key) {
      console.log(this.optionsInfo['mergeColInfo'][key])
    },

    handleChangeScroll(val) {
      if (val) {
        Reflect.set(this.optionsInfo, 'ellipsisState', false);
        Reflect.set(this.optionsInfo, 'patientSpace', true);
      } else {
        Reflect.set(this.optionsInfo, 'patientSpace', false);
      }
    },

    // 拖动结束
    handleDragEnd() {
    },

    // 改变弹层字号
    handleChangeFontSize(val, type) {
      if (type === 'current') {
        this.optionsInfo['layerInfo']['waiting']['fontSize'] = val
      } else if (type === 'waiting') {
        this.optionsInfo['layerInfo']['current']['fontSize'] = val
      }
    },

    // 总条数
    handleTotal(val) {
      let {multiple} = (this.optionsInfo)
      this.optionModel.rowNumber = multiple * val;
    },

    // 科室诊室&号别--科室和好别不能共存
    handleChange(val, row) {
      let value = (row.value);
      let {checkList} = (this.optionsInfo);
      if (value === 1) {
        if (val) {
          this.$lodash.pull(checkList, 2);
        }
      }
      if (value === 2) {
        if (val) {
          this.$lodash.pull(checkList, 1);
        }
      }
    },

    // 医生和号别二选一--方便拓展采选多选的形式
    handleRuleChange(val, row) {
      let value = (row.value);
      let {queryRule} = (this.optionsInfo);
      if (val) {
        if (value === 1) {
          if (val) {
            this.$lodash.pull(queryRule, 2);
          }
        }
        if (value === 2) {
          if (val) {
            this.$lodash.pull(queryRule, 1);
          }
        }
      } else {
        if (!(queryRule && !!(queryRule.length))) {
          queryRule.push(value)
          this.$message({
            message: '数据规则不可为空',
            type: 'warning',
          })
        }
      }
    },

    handleChangeWidth(event, key) {
      console.log(event)
      console.log(key)
    },

    handleCheckboxClick(event) {
      // 检查点击事件的目标是否为label元素
      if (event.target.tagName.toLowerCase() === 'label') {
        // 阻止事件冒泡，这样就不会触发el-checkbox-group的点击事件处理函数
        event.stopPropagation();
      }
    }

  },

  watch: {
    // 组件的所有信息
    optionModel: {
      handler: function (val) {
        this.optionsInfo = (val[val.config]);
      },
      deep: true,
      immediate: true
    }
  }

}
</script>

<style lang="scss" scoped>
.switching-screen {
  :deep(.el-input-number__decrease) {
    margin-top: 1px;
  }

  :deep(.el-input-number__increase) {
    margin-top: 1px;
  }
}

.call-patient-set {
  display: flex;
  flex-direction: column;

  :deep(.el-form-item__label) {
    @include fontWeight();
    width: 100% !important;
  }

  :deep(.el-form-item__content) {
    margin-left: 0 !important;

    .el-checkbox-group {
      display: flex;
      flex-direction: column;
    }

    .el-select {
      width: 100%;
    }
  }
}

.tooltip-area {
  :deep(.el-form-item__content) {
    .wrap{
      display: flex;
      align-items: center;
      align-self: center;
      .right {
        .el-button {
          padding: 9px 8px;
          border: none;
          font-size: 18PX;
          color: #E6A23C;

          &:hover {
            background: transparent !important;
          }
        }
      } ;
    }

  }
}

.col-info {
  :deep(.el-form-item__content) {
    margin-left: 1px !important;

    .title {
      width: 100%;
    }

    .el-checkbox__label {
      width: auto;
    }


    .el-icon-thumb {
      position: relative;
      top: 8px;
      padding-left: 10px;
      font-size: 18px;
      text-align: center;
    }

    .el-checkbox {
      width: calc(100% - 32px);
    }
  }
}

//号别简称
.register-info {
  :deep(.el-form-item__content) {
    margin-left: 1px !important;

    .title {
      width: 100%;
    }

    .el-radio-group {
      .el-radio {
        width: 100%;
        padding: 8px 0;
      }
    }
  }
}

.row-option {
  :deep(.el-checkbox) {
    display: flex;
    flex-direction: row;

    .el-checkbox__input {
      display: flex;
      align-self: flex-start;
      align-items: flex-start;
    }

    .el-checkbox__label {
      display: flex;
      flex-direction: row;

      .setting-info {
        display: flex;
        flex-direction: column;

        .el-input {
          width: 100%;
          margin-bottom: 20px;

          input[type="number"] {
            line-height: 1px !important;
          }
        }

        .el-input-number {
          width: 100%;
        }

        .el-input__inner {
          padding-right: 0 !important;
        }
      }
    }
  }
}

.column-area {
  display: flex;
  flex-direction: column;

  :deep(.el-form-item__label) {
    width: 100% !important;
    margin-bottom: 10px;
  }

  :deep(.el-form-item__content) {
    width: 100%;
    margin-left: 0 !important;

    .el-radio-group {
      width: 100%;
      display: flex;
      flex-direction: column;

      .el-radio {
        margin-bottom: 10px;
      }
    }
  }

}

.wait-patient-set {
  display: flex;
  flex-direction: column;

  :deep(.el-form-item__label) {
    width: 100% !important;
  }

  :deep(.el-form-item__content) {
    margin-left: 0 !important;;

    .el-radio-group {
      display: flex;
      flex-direction: column;

      .el-radio {
        padding: 10px 0;
      }
    }
  }

}
</style>
